<?php

namespace App\models\forum;

use App\models\user\User;
use Illuminate\Database\Eloquent\Model;

/**
 * App\models\forum\Moderator
 *
 * @property int $id
 * @property int $plate_id
 * @property int $uid
 * @property \Carbon\Carbon $created_at
 * @property \Carbon\Carbon $updated_at
 * @property-read \App\models\user\User $user
 * @property-read \App\models\forum\Partition $plate
 * @method static \Illuminate\Database\Query\Builder|\App\models\forum\Moderator whereId($value)
 * @method static \Illuminate\Database\Query\Builder|\App\models\forum\Moderator wherePlateId($value)
 * @method static \Illuminate\Database\Query\Builder|\App\models\forum\Moderator whereUid($value)
 * @method static \Illuminate\Database\Query\Builder|\App\models\forum\Moderator whereCreatedAt($value)
 * @method static \Illuminate\Database\Query\Builder|\App\models\forum\Moderator whereUpdatedAt($value)
 * @mixin \Eloquent
 */
class Moderator extends Model
{
    public function user(){
        return $this->belongsTo(User::class, 'uid', 'id');
    }

    public function plate(){
        return $this->belongsTo(Partition::class,  'plate_id', 'id');
    }

    public static function hasAdmin(int $uid){
        return count(self::where('uid', $uid)->get()) > 0 ? true : false;
    }
}
